<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <%@ include file="../../static/_head.jsp" %>
    <title>管理员权限</title>
</head>
<body>

<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span> 管理员管理
    <span class="c-gray en">&gt;</span> 管理员权限
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" id="btn-refresh"><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>

<div class="panel panel-default">
    <div class="panel-header">导航列表</div>
    <div class="panel-body">
        <div class="page-container">
            <div class="text-c">
                <span class="select-box inline">
                    <select class="select" id="state" name="state">
                        <option value="">全部</option>
                        <option value="0" <c:if test="${state eq '0'}">selected</c:if>>禁用</option>
                        <option value="1" <c:if test="${state eq '1'}">selected</c:if>>启用</option>
                    </select>
                </span>
                <input type="text" id="name" placeholder="名称" style="width:250px" class="input-text" name="name" value="${name}">
                <button class="btn btn-success" onclick="selectBtn('/user/permission/index')"><i class="Hui-iconfont">&#xe665;</i>
                    开始搜索
                </button>
            </div>
            <div class="cl pd-5 bg-1 bk-gray mt-20">
                <span class="l">
                    <a href="javascript:void(0)" onclick="datadel_all_level_first()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
                    <a href="javascript:void(0);" onclick="permission_add('新增导航','/user/permission/add','','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 新增导航</a>
                </span>
            </div>
            <div class="mt-20">
                <table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
                    <thead>
                    <tr class="text-c">
                        <th><input type="checkbox"></th>
                        <th>序号</th>
                        <th>代码</th>
                        <th>状态</th>
                        <th>名称</th>
                        <th>图标</th>
                        <th>排序</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${pageInfo.list}" var="permission" varStatus="pindex">
                        <tr class="text-c">
                            <td><input type="checkbox" value="${permission.id}|${permission.name}" name="isCkeckbox">
                            </td>
                            <td>${pindex.index+1}</td>
                            <td>${permission.code}</td>
                            <td>
                                <c:if test="${permission.state==1}">
                                    <span class="label label-success radius">已启用</span>
                                </c:if>
                                <c:if test="${permission.state==0}">
                                    <span class="label label-warning radius">已禁用</span>
                                </c:if>
                            </td>
                            <td>${permission.name}</td>
                            <td><i class="Hui-iconfont">${permission.icon}</i></td>
                            <td>${permission.sort}</td>
                            <td class="f-14 td-manage">
                                <c:if test="${permission.state==1}">
                                    <a style="text-decoration:none" href="javascript:void(0);" onclick="permission_state('${permission.id}|${permission.name}')" class="ml-5" title="禁用"><i class="Hui-iconfont">&#xe631;</i></a>
                                </c:if>
                                <c:if test="${permission.state==0}">
                                    <a style="text-decoration:none" href="javascript:void(0);" onclick="permission_state('${permission.id}|${permission.name}')" class="ml-5" title="启用"><i class="Hui-iconfont">&#xe6e6;</i></a>
                                </c:if>

                                <a style="text-decoration:none" href="javascript:void(0);" onclick="permission_edit('${permission.id}','导航编辑','/user/permission/update','','510')" class="ml-5" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>
                                <a style="text-decoration:none" href="javascript:void(0);" onclick="permission_delete('${permission.id}|${permission.name}')" class="ml-5" title="删除"><i class="Hui-iconfont">&#xe609;</i></a>
                                <a style="text-decoration:none" href="javascript:void(0);" data-title="${permission.name}-菜单" data-href="/user/permission/menu/index?parentId=${permission.id}" onclick="Hui_admin_tab(this)" title="点击跳转菜单列表"><i class="Hui-iconfont">&#xe63d;</i></a>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <input type="hidden" name="total" id="total" value="${pageInfo.total}">
                <input type="hidden" name="pageNum" id="pageNum" value="${pageInfo.pageNum}">
                <input type="hidden" name="pages" id="pages" value="${pageInfo.pages}">
                <div id="kkpager"></div>
            </div>
        </div>
    </div>
</div>
<%@ include file="../../static/_footer.jsp" %>
<script>
    /*添加导航*/
    function permission_add(title, url, w, h) {
        layer_show(title, url, w, h);
    }

    /*查询*/
    function selectBtn(url) {
        var pageNum = $("*[ name='pageNum']").val()
        refresh(pageNum);
    }

    /*删除选中*/
    function datadel_all_level_first() {
        var chk_id = [], chk_name = [];

        $('input[name="isCkeckbox"]:checked').each(function () {
            var temp = $(this).val().split("|");
            chk_id.push(temp[0]);
            chk_name.push(temp[1]);
        });

        if (chk_id.length == 0) {
            layer.msg("没有选中的数据");
        } else {
            layer.confirm('是否删除名称为【' + chk_name + "】的数据", {
                btn: ['确定', '取消']
            }, function () {
                $.ajax({
                    url: "/user/permission/delete",
                    method: "POST",
                    data: "chkids=" + chk_id,
                    success: function (data) {
                        if (data.code == 200) {
                            layer.msg("删除成功", function () {
                                var pageNum = $("*[ name='pageNum']").val()
                                refresh(pageNum);
                            })
                        } else {
                            layer.msg("删除失败", function () {
                                var pageNum = $("*[ name='pageNum']").val()
                                refresh(pageNum);
                            })
                        }
                    }
                });
            });
        }
    }

    /*编辑当前数据*/
    function permission_edit(id, title, url, w, h) {
        layer_show(title, url+"?id="+id, w, h);
    }

    /*删除当前数据*/
    function permission_delete(data) {
        var temp = data.split("|");
        layer.confirm('是否删除名称为【' + temp[1] + "】的数据", {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                url: "/user/permission/delete",
                method: "POST",
                data: "chkids=" + temp[0],
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg("删除成功", function () {
                            var pageNum = $("*[ name='pageNum']").val()
                            refresh(pageNum);
                        })
                    } else {
                        layer.msg("删除失败", function () {
                            var pageNum = $("*[ name='pageNum']").val()
                            refresh(pageNum);
                        })
                    }
                }
            });
        });
    }

    /*修改状态*/
    function permission_state(id) {
        var temp = id.split("|");
        layer.confirm('是否更改名称为【' + temp[1] + "】的状态", {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                url: "/user/permission/state",
                method: "POST",
                data: "id=" + temp[0],
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg("修改成功", function () {
                            var pageNum = $("*[ name='pageNum']").val()
                            refresh(pageNum);
                        })
                    } else {
                        layer.msg("修改失败", function () {
                            var pageNum = $("*[ name='pageNum']").val()
                            refresh(pageNum);
                        })
                    }
                }
            });
        });
    }

    /*分页插件*/
    $(function () {
        var totalPage = $("*[ name='pages']").val();
        var totalRecords = $("*[ name='total']").val();
        var pageNo = $("*[ name='pageNum']").val();
        kkpager.generPageHtml({
            pno: pageNo,
            total: totalPage,
            totalRecords: totalRecords,
            mode: 'click',
            click: function (next) {
                refresh(next);
                return false;
            }
        });
    });

    /*刷新页面*/
    function refresh(pageNum) {
        var state = $("*[ name='state']").val(), name = $("*[ name='name']").val();
        console.log(state);
        var params = "?1=1";
        if (name!=undefined && name!=""){
            params += "&name="+name;
        }
        if (state != undefined && state!="") {
            params += "&state=" + state;
        }
        return location.href = "/user/permission/index" + params + "&pageNum=" + pageNum;
    }
</script>
</body>
</html>
